//
//  CZStatusForwardCell.swift
//  crkWeibo
//
//  Created by 陈荣科 on 15/12/28.
//  Copyright © 2015年 crk. All rights reserved.
//

import UIKit

class CZStatusForwardCell: CZStatusCell {
    //MARK: - 属性
    /// 微博模型，用于显示转发微博的文本和转发微博的图片
    
    ///覆盖父类的属性 
    //1、添加override 关键字
    //2、必须实现属性监视器
    //3、先调用父类的属性监视器，在调用子类的属性监视器
   override var status: CZStatus? {
        didSet{
        
            if let forwarStatus = status?.retweeted_status{
            
                let text = "@\(forwarStatus.user!.screen_name!): \(forwarStatus.text!)"
                forwardLabel.text = text
            }
        }
    }

    override func prepareUI() {
        super.prepareUI()
        
        //添加子控件
        contentView.addSubview(bkgButton)
        contentView.addSubview(forwardLabel)
        contentView.sendSubviewToBack(bkgButton)
        
        //添加约束
        //背景左上角的约束
        bkgButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -8, y: 8))
        //背景右上角的约束
        bkgButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        
        //被转发的微博文本label，在背景按钮内部，左上角
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: bkgButton, size: nil, offset: CGPoint(x: 8, y: 8))
        
        //转发微博文本label宽度
       contentView.addConstraint(NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * 8))
        
        // 微博配图
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: 8))
        
        // 获取微博配图视图的宽高约束
        // 注意: 设置约束的时候需要设置 size， 不然框架不会添加宽高约束,拿不到宽高约束
        pictureViewWidthCon = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureViewHeightCon = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        
    }
    
    
    ///MAKR: - 懒加载
    //背景
    private lazy var bkgButton: UIButton = {
    
        let button = UIButton()
        
        //设置背景颜色
        button.backgroundColor = UIColor(white: 0.88, alpha: 1)
    
        return button
    }()
    
    //转发微博的文本内容
    private lazy var forwardLabel: UILabel = {
        let label = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
        
        //设置显示多行
        label.numberOfLines = 0
        return label
    }()
    
}
